cmake_minimum_required(VERSION 3.2)

message(STATUS "Configuring apps")

file(GLOB TARGETS_SRC
	#"*.cpp"
	#"test/*.cpp"
)

if (NOT(${NO_ROS}))
	#list(REMOVE_ITEM TARGETS_SRC "${CMAKE_CURRENT_LIST_DIR}/ros_*")
	file(GLOB TARGETS_SRC_ROS
		#"ros/kacanopen.cpp"
		#"ros/kacanopen_param.cpp"
		"ros/kacanopen_new.cpp"
	)
	list(APPEND TARGETS_SRC ${TARGETS_SRC_ROS})
endif()

foreach(TARGET_SRC ${TARGETS_SRC})

	get_filename_component(TARGET_NAME ${TARGET_SRC} NAME_WE)
	set(TARGET_NAME "kacanopen_apps_${TARGET_NAME}")
	add_executable(${TARGET_NAME} ${TARGET_SRC})
	set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 17)

	ament_target_dependencies(${TARGET_NAME}
        rclcpp
        std_msgs
        agv_msgs
        agv_srvs  
        sensor_msgs 
        common
    )

	target_link_libraries(${TARGET_NAME}
        kacanopen_core
        kacanopen_master
        yaml-cpp
        ${common_LIBRARIES}
    )
    
	if (NOT(${NO_ROS}))
		target_link_libraries(${TARGET_NAME} kacanopen_ros_bridge)
	endif()
	
	list(APPEND KACANOPEN_APPS_TARGET_NAMES ${TARGET_NAME})
endforeach(TARGET_SRC ${TARGETS_SRC})

# Install
if (${INSTALL_APPS})
	kacanopen_install("${KACANOPEN_APPS_TARGET_NAMES}" FALSE)
endif()

